﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;

namespace YouYi.YingShengBack.Repository
{
    public class DbCpntextFactory<TS> where TS : DbContext, new()
    {
        /// <summary>
        /// 返回数据库对象
        /// </summary>
        /// <returns></returns>
        public static DbContext GetDBContext()
        {
            var dbContext = CallContext.GetData(typeof(TS).Name) as DbContext;
            if (dbContext != null)
            {
                return dbContext;
            }
            else
            {
                dbContext = new TS();
                CallContext.SetData(typeof(TS).Name, dbContext);
            }

            return dbContext;
        }
    }
}
